package com.cloudspace.jindun.activity.dianhua;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.android.volley.error.VolleyError;
import com.cloudspace.jindun.R;
import com.cloudspace.jindun.activity.CustomTitleBaseActivity;
import com.cloudspace.jindun.model.RemarkResult;
import com.cloudspace.jindun.network.api.API;
import com.cloudspace.jindun.network.base.ApiCallback;
import com.cloudspace.jindun.user.UserSessionManager;
import com.cloudspace.jindun.utils.ToastMaker;

import static java.net.HttpURLConnection.HTTP_OK;

/**
 * Created by zengxianhua on 17/1/6.
 */

public class RemarkManActivity extends CustomTitleBaseActivity{
    private Button remarkBtn;
    private EditText edit;

    private Intent intent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_link_man_remark_name);
        getTitleBar().setSimpleMode(getResources().getString(R.string.changeRemarkName));

        edit = (EditText) findViewById(R.id.phone_et_newRemark);
        remarkBtn = (Button) findViewById(R.id.phone_btn_newRemark);
        remarkBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                remarkPerson();
            }
        });

        intent = getIntent();
    }

    public static final String TAG = RemarkManActivity.class.getSimpleName();

    private void remarkPerson() {
        if (intent == null){
            return;
        }

        final String remark = edit.getEditableText().toString().trim();
        String id = intent.getStringExtra("id");
        API.getInstance().getOrgApi().remarkFriend(TAG, UserSessionManager.getInstance().getUserId(), id,remark, new ApiCallback<RemarkResult>() {
            @Override
            public void handleResult(RemarkResult result, VolleyError error) {
                if (error == null && result != null && result.getStatus() == HTTP_OK){
                    Intent newIntent = new Intent();
                    newIntent.putExtra("remark", remark);
                    setResult(RESULT_OK, newIntent);
                    ToastMaker.showToastShort(getResources().getString(R.string.remark_success));
                    finish();
                }
            }
        });
    }
}
